﻿/*----------------------------------------------------------------
 * 
 * 版权所有：Copyright (C) 2012 
 * 
 * 文件名：ProductController.cs
 * 文件功能描述：
 * 
 * 
 * 作 者：zhangq
 * 邮 箱：zhangqiang@bamabest.com
 * 日 期：2013-02-25 02:14:13
 * 
 * 
 * 修改标识： Author
 * 修改描述： 相关描述
 * 
 * ---------------------------------------------------------------- */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Common.Extensions.OrderBy;
using Common.Extensions.Where;
using DomainModel;
using EmitMapper;
using IManager;
using Webdiyer.WebControls.Mvc;
using WebPlatform.Models;

namespace WebPlatform.Areas.CPP.Controllers
{

    /// <summary>
    /// 
    /// </summary>
    public class CProductController : Controller
    {
        /// <summary>
        /// 产品业务
        /// </summary>
        public IManagerProduct IMProduct { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public ActionResult Index()
        {
            return View();
        }



        /// <summary>
        /// 
        /// </summary>
        /// <param name="filters"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public ActionResult FilterProducts(string filters, string filterType, int page = 1, int pageSize = 15)
        {
            //TODO
            var p = PredicateExtension.True<ProductInfo>();
            p = p.And(u => u.IsChecked == 1);
            if (!string.IsNullOrEmpty(filters))
            {
                if (filterType == "2")
                {
                    p = p.And(u => u.Company.Name.Contains(filters));
                }
                else if (filterType=="9")
                {
                    p = p.And(u => u.Partition.Name.Contains(filters));
                }
                else
                {
                    p = p.And(u => u.KeyWords.Contains(filters));
                }

            }
            var count = IMProduct.LoadProductCount(p);
            var list = IMProduct.LoadProductAll(p, page, pageSize, new OrderByExpression<ProductInfo, int>(u => u.Id));

            PagedList<ProductInfo> plist =
                new PagedList<ProductInfo>(list, page, pageSize, count);
            ViewBag.filters = filters;
            return View(plist);
        }

        
    }
}
